<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>个人中心 - 列车车次管理系统</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.0/font/bootstrap-icons.css">
    <link rel="stylesheet" href="/css/styles.css">
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-dark bg-primary">
    <div class="container">
        <a class="navbar-brand" href="/">
            <i class="fas fa-train me-2"></i>列车车次管理系统
        </a>
        <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
            <span class="navbar-toggler-icon"></span>
        </button>
        <div class="collapse navbar-collapse" id="navbarNav">
            <ul class="navbar-nav me-auto">
                <li class="nav-item">
                    <a class="nav-link" href="/">首页</a>
                </li>                <li class="nav-item">
                    <a class="nav-link" href="/user/booking">车票预订</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="/user/tickets">我的车票</a>
                </li>
            </ul>
            <ul class="navbar-nav" id="authNav">
                <!-- 动态填充登录状态 -->
            </ul>
        </div>
    </div>
</nav>

<div class="container mt-4">
    <div class="row">
        <!-- 左侧导航 -->
        <div class="col-md-3">
            <div class="card">
                <div class="card-header">
                    <h6 class="mb-0"><i class="bi bi-person-circle me-2"></i>个人中心</h6>
                </div>
                <div class="list-group list-group-flush">
                    <a href="#profile" class="list-group-item list-group-item-action active" data-tab="profile">
                        <i class="bi bi-person me-2"></i>个人信息
                    </a>
                    <a href="#security" class="list-group-item list-group-item-action" data-tab="security">
                        <i class="bi bi-shield-lock me-2"></i>安全设置
                    </a>
                    <a href="#orders" class="list-group-item list-group-item-action" data-tab="orders">
                        <i class="bi bi-receipt me-2"></i>订单历史
                    </a>
                </div>
            </div>
        </div>

        <!-- 右侧内容 -->
        <div class="col-md-9">
            <!-- 个人信息标签页 -->
            <div id="profile-tab" class="tab-content active">
                <div class="card">
                    <div class="card-header">
                        <h5 class="mb-0"><i class="bi bi-person me-2"></i>个人信息</h5>
                    </div>
                    <div class="card-body">
                        <div id="profileAlert" class="alert alert-success d-none" role="alert">
                            个人信息更新成功
                        </div>
                        
                        <form id="profileForm">
                            <div class="row">
                                <div class="col-md-6">
                                    <div class="mb-3">
                                        <label for="username" class="form-label">用户名</label>
                                        <input type="text" class="form-control" id="username" readonly>
                                    </div>
                                </div>
                                <div class="col-md-6">
                                    <div class="mb-3">
                                        <label for="userRole" class="form-label">用户角色</label>
                                        <input type="text" class="form-control" id="userRole" readonly>
                                    </div>
                                </div>
                            </div>
                            
                            <div class="row">
                                <div class="col-md-6">
                                    <div class="mb-3">
                                        <label for="name" class="form-label">真实姓名 <span class="text-danger">*</span></label>
                                        <input type="text" class="form-control" id="name" required>
                                    </div>
                                </div>
                                <div class="col-md-6">
                                    <div class="mb-3">
                                        <label for="idCard" class="form-label">身份证号 <span class="text-danger">*</span></label>
                                        <input type="text" class="form-control" id="idCard" required>
                                    </div>
                                </div>
                            </div>
                            
                            <div class="row">
                                <div class="col-md-6">
                                    <div class="mb-3">
                                        <label for="phone" class="form-label">手机号码 <span class="text-danger">*</span></label>
                                        <input type="tel" class="form-control" id="phone" required>
                                    </div>
                                </div>
                                <div class="col-md-6">
                                    <div class="mb-3">
                                        <label for="email" class="form-label">电子邮箱</label>
                                        <input type="email" class="form-control" id="email">
                                    </div>
                                </div>
                            </div>
                            
                            <div class="mb-3">
                                <label for="createTime" class="form-label">注册时间</label>
                                <input type="text" class="form-control" id="createTime" readonly>
                            </div>
                            
                            <button type="submit" class="btn btn-primary">
                                <i class="bi bi-check-circle me-2"></i>保存修改
                            </button>
                        </form>
                    </div>
                </div>
            </div>

            <!-- 安全设置标签页 -->
            <div id="security-tab" class="tab-content d-none">
                <div class="card">
                    <div class="card-header">
                        <h5 class="mb-0"><i class="bi bi-shield-lock me-2"></i>安全设置</h5>
                    </div>
                    <div class="card-body">
                        <div id="passwordAlert" class="alert alert-success d-none" role="alert">
                            密码修改成功
                        </div>
                        
                        <form id="passwordForm">
                            <div class="mb-3">
                                <label for="currentPassword" class="form-label">当前密码 <span class="text-danger">*</span></label>
                                <input type="password" class="form-control" id="currentPassword" required>
                            </div>
                            
                            <div class="mb-3">
                                <label for="newPassword" class="form-label">新密码 <span class="text-danger">*</span></label>
                                <input type="password" class="form-control" id="newPassword" required minlength="6">
                                <div class="form-text">密码长度至少为6个字符</div>
                            </div>
                            
                            <div class="mb-3">
                                <label for="confirmNewPassword" class="form-label">确认新密码 <span class="text-danger">*</span></label>
                                <input type="password" class="form-control" id="confirmNewPassword" required>
                            </div>
                            
                            <button type="submit" class="btn btn-warning">
                                <i class="bi bi-key me-2"></i>修改密码
                            </button>
                        </form>
                        
                        <hr class="my-4">
                        
                        <h6>账户安全</h6>
                        <div class="row">
                            <div class="col-md-6">
                                <div class="card bg-light">
                                    <div class="card-body text-center">
                                        <i class="bi bi-shield-check text-success" style="font-size: 2rem;"></i>
                                        <h6 class="mt-2">账户状态</h6>
                                        <span class="badge bg-success">正常</span>
                                    </div>
                                </div>
                            </div>
                            <div class="col-md-6">
                                <div class="card bg-light">
                                    <div class="card-body text-center">
                                        <i class="bi bi-clock-history text-info" style="font-size: 2rem;"></i>
                                        <h6 class="mt-2">最后登录</h6>
                                        <small class="text-muted" id="lastLoginTime">加载中...</small>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <!-- 订单历史标签页 -->
            <div id="orders-tab" class="tab-content d-none">
                <div class="card">
                    <div class="card-header d-flex justify-content-between align-items-center">
                        <h5 class="mb-0"><i class="bi bi-receipt me-2"></i>订单历史</h5>
                        <div>
                            <select id="orderStatusFilter" class="form-select form-select-sm">
                                <option value="">全部状态</option>
                                <option value="CONFIRMED">已确认</option>
                                <option value="PENDING">待确认</option>
                                <option value="CANCELLED">已取消</option>
                            </select>
                        </div>
                    </div>
                    <div class="card-body">
                        <div id="ordersLoading" class="text-center py-4">
                            <div class="spinner-border text-primary" role="status">
                                <span class="visually-hidden">Loading...</span>
                            </div>
                            <p class="mt-2">正在加载订单历史...</p>
                        </div>
                        
                        <div id="ordersContent" class="d-none">
                            <div class="table-responsive">
                                <table class="table table-hover">
                                    <thead>
                                        <tr>
                                            <th>订单号</th>
                                            <th>车次</th>
                                            <th>行程</th>
                                            <th>日期时间</th>
                                            <th>乘客</th>
                                            <th>金额</th>
                                            <th>状态</th>
                                        </tr>
                                    </thead>
                                    <tbody id="ordersTable">
                                        <!-- 动态加载订单数据 -->
                                    </tbody>
                                </table>
                            </div>
                        </div>
                        
                        <div id="noOrdersArea" class="text-center py-5 d-none">
                            <i class="bi bi-receipt" style="font-size: 4rem; color: #dee2e6;"></i>
                            <h5 class="text-muted mt-3">暂无订单记录</h5>
                            <p class="text-muted">您还没有任何订单记录</p>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<footer class="bg-light text-center text-lg-start mt-5">
    <div class="text-center p-3" style="background-color: rgba(0, 0, 0, 0.05);">
        © 2025 列车车次管理系统 -
        <a class="text-dark" href="/">upup.com</a>
    </div>
</footer>

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="/js/auth.js"></script>
<script>
    $(document).ready(function() {
        // 更新导航栏认证状态
        updateAuthNav();
        
        // 检查用户是否已登录，如未登录则重定向
        getCurrentUser().catch(function() {
            window.location.href = '/custom-login?redirect=' + encodeURIComponent(window.location.pathname);
        });
    });
</script>
</body>
</html>
